package oj;

import java.util.Scanner;

public class Day19F {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            int n=sc.nextInt();
            int count=0;
            if(n==0){
                break;
            }
            if(n==1){
                System.out.println(0);
            }
            while (n!=1){
                count+=n/3;
                n=n%3+n/3;
                if(n==2){
                    count++;
                    n=(n+1)/3;
                }
            }
            System.out.println(count);
        }
    }
}
